package cc.decat.escript.object;

public class ESBooleanObject extends ESObject {

    public static ESObject fromValue(boolean b) {
        return b ? ESConstObjects.TRUE : ESConstObjects.FALSE;
    }

    private boolean value;

    public ESBooleanObject(boolean value) {
        super(ESBooleanType.getInstance());
        this.value = value;
    }

    public boolean getValue() {
        return this.value;
    }

    @Override
    public boolean equals(Object obj) {
        return this == obj;
    }

    @Override
    public int hashCode() {
        return Boolean.hashCode(value);
    }
}

class ESBooleanType extends ESType {

    private static final ESBooleanType instance = new ESBooleanType();

    public static ESBooleanType getInstance() {
        return instance;
    }

    private ESBooleanType() {
        super("Boolean");
    }

    @Override
    public ESObject str(ESObject x) {
        return ESStringObject.fromValue(String.valueOf(((ESBooleanObject) x).getValue()));
    }
}